/*
 * COPYRIGHT:	2010 Christopher Smith, licenced under the GNU GPL v2; see COPYING in the top level directory
 * PROJECT:		sdedit launcher
 * FILE:		launcher.cpp
 * PURPOSE:		sdeditg launcher
 *				finds and calls SdEditWinMain
 */

#include <windows.h>

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	int (__stdcall *SdEditWinMain)() = NULL;

	HMODULE Sdlib = LoadLibrary(L"sdeditg.dll");

	if(!Sdlib)
		Sdlib = LoadLibrary(L"aclui.dll");

	if(Sdlib)
		SdEditWinMain = reinterpret_cast<int (__stdcall *)()>(GetProcAddress(Sdlib, "SdEditWinMain"));
	
	//MessageBox(NULL, L"Wait", L"", MB_OK);

	if(!SdEditWinMain)
	{
		MessageBox(NULL, L"sdeditg.dll from SD Edit is required", L"Critical SD Edit component missing", MB_OK);
		return ERROR_FILE_NOT_FOUND;
	}

	int ret = SdEditWinMain();

	FreeLibrary(Sdlib);

	return ret;
}